fix: route Sentry events into a frontend-visible project and harden envelope parsing#335
Merged
Merged
Conversation
Closed
There was a problem hiding this comment.
Pull request overview
This PR fixes Sentry ingestion compatibility and frontend visibility by ensuring Sentry events are associated with projects that exist in the projects table, improving envelope parsing correctness (length-prefixed items), handling /envelope/ + /store/ trailing-slash paths, and returning a Sentry-compatible ingest acknowledgement body.
Changes:
- Auto-register non-
defaultproject keys during event ingestion so newly seen Sentry project IDs become selectable/visible in the UI. - Rework Sentry envelope parsing to honor item
length(supporting multi-line payloads) and add coverage for malformed/edge cases. - Make detection/matching robust to trailing slashes and return
{"id":"<event_id>"}for Sentry ingests while preserving{"status":true}for other modules.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| modules/sentry/handler.go | Accept /envelope/ and /store/ paths with trailing slashes for Sentry matching. |
| modules/sentry/handler_test.go | Adds tests for trailing-slash matching and multiline, length-prefixed envelope payloads. |
| modules/sentry/envelope.go | Replaces newline-only splitting with a length-aware envelope item parser. |
| modules/sentry/envelope_test.go | Adds comprehensive tests for envelope parsing (length, multiline, multi-item, malformed headers, overruns). |
| internal/server/http/ingestion.go | Centralizes ingestion ack responses; returns Sentry-shaped {"id":...} for Sentry events. |
| internal/server/http/ingestion_test.go | Adds tests ensuring Sentry vs non-Sentry ingest responses and project auto-creation behavior. |
| internal/server/http/event_service.go | Auto-registers non-default projects in DB during ingestion. |
| internal/server/http/event_service_test.go | Adds coverage for project auto-registration and ensuring default project seed isn’t overwritten. |
| internal/server/http/detect.go | Strips trailing slashes before Sentry path suffix detection. |
| internal/server/http/detect_test.go | Adds trailing-slash detection tests for Sentry endpoints. |
| internal/server/http/api_test.go | Updates NewEventService construction to pass DB handle. |
| internal/app/app.go | Updates NewEventService construction to pass DB handle. |
| cmd/buggregator/main.go | Updates NewEventService construction to pass DB handle. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced May 12, 2026
…nvelope parsing
Sentry events arrived under the Sentry project ID parsed from the DSN
path, which was never registered as a buggregator project — the frontend
filtered them out of the events list and the sidebar dot stayed unlit.
EventService now INSERT OR IGNORE's unknown project keys on ingest, the
envelope parser honors per-item length headers (multi-line payloads),
trailing slashes on /envelope/ and /store/ are recognised, and Sentry
SDKs receive {id: event_id} on a successful ingest. Issue #321.
d36df44 to
7efb3fe
Compare
Per Copilot review on #335: pos+ih.Length can overflow signed int when a crafted envelope declares length close to math.MaxInt, wrapping to a negative bound that passes the additive check and then panics when slicing. Swap to a subtractive bound (ih.Length <= len(body)-pos) and add a regression test that triggers the overflow path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Issue #321 — fixes the dominant Sentry breakage where exceptions appeared in the "Group by type" pane but were missing from the events list, timeline, and sidebar dot, plus several smaller server-side issues uncovered along the way.
Why
The Sentry handler stored canonical events under the Sentry project ID parsed from the DSN path (
/api/123/envelope/→"123"). Theprojectstable is seeded only withdefault, so the frontend filtered every Sentry event out of the events list (it only renders events whoseprojectmatches the active project key) and the sidebar dot never lit up. Several adjacent SDK-compat issues fell out while tracing the bug.How
EventServicenow takes*sql.DB;HandleIncomingrunsINSERT OR IGNORE INTO projects (key, name)for any project key that isn'tdefault. The frontend already refreshes its project list when an unknown project arrives, so events become visible immediately.length. The previous parser split solely on\n, which corrupts items whose payloads contain literal newlines. The new parser readslengthbytes when present and falls back to newline-delimited payloads otherwise./api/{id}/envelope/; theMatchpredicate anddetectEventTypenow strip a trailing slash before suffix-matching./api/{id}/envelope/and/api/{id}/store/now reply with{"id":"<event_id>"}; other modules keep the legacy{"status":true}body.Testing
Covered by automated tests:
internal/server/http/event_service_test.go—AutoRegistersProject,DefaultProjectIsNotRewritteninternal/server/http/ingestion_test.go—SentryResponse_ReturnsEventID,SentryResponse_TransactionOnly_ReturnsSentryShape,NonSentryResponse_KeepsLegacyShape,AutoCreatesSentryProjectinternal/server/http/detect_test.go— trailing-slash/envelope/and/store/casesmodules/sentry/envelope_test.go— length-prefixed, multi-line, multi-item, malformed-header, length-overrunmodules/sentry/handler_test.go—Matchtrailing-slash cases,Handle_EnvelopeMultilinePayloadgo test ./... -count=1andgo vet ./...clean.